#include "stdafx.h"
#include "CListCtrl_EnableToolTip.h"

BEGIN_MESSAGE_MAP(CListCtrl_EnableToolTip, CListCtrl)
	ON_NOTIFY_EX(TTN_NEEDTEXTA, 0, OnToolNeedText)
	ON_NOTIFY_EX(TTN_NEEDTEXTW, 0, OnToolNeedText)
END_MESSAGE_MAP()

void CListCtrl_EnableToolTip::PreSubclassWindow()
{
	CListCtrl_ToolTip::PreSubclassWindow();

	// Disable the CToolTipCtrl of CListCtrl so it won't disturb the CWnd tooltip
	GetToolTips()->Activate(FALSE);

	// Activates the standard CWnd tooltip functionality
	VERIFY( EnableToolTips(TRUE) );
}

 INT_PTR CListCtrl_EnableToolTip::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
 {
	CPoint pt(GetMessagePos());
	ScreenToClient(&pt);
	if (!ShowToolTip(pt))
		return -1;

	int nRow, nCol;
	CellHitTest(pt, nRow, nCol);

	//Get the client (area occupied by this control
	RECT rcClient;
	GetClientRect( &rcClient );

	//Fill in the TOOLINFO structure
	pTI->hwnd = m_hWnd;
	pTI->uId = (UINT) (nRow * 1000 + nCol);
	pTI->lpszText = LPSTR_TEXTCALLBACK;	// Send TTN_NEEDTEXT when tooltip should be shown
	pTI->rect = rcClient;

	return pTI->uId; // Must return a unique value for each cell (Marks a new tooltip)
 }

 CString CListCtrl_EnableToolTip::GetToolTipText( int nRow, int nCol )
 {
	CString strToolTipText = _T("");
	m_mapTooltips.Lookup(nRow, strToolTipText);
	return strToolTipText;
 }

 void CListCtrl_EnableToolTip::SetToolTipText( int nIndex, LPCTSTR lpszText )
 {
	m_mapTooltips.SetAt(nIndex, lpszText);	
 }
